const Words = require('./db').Words 
const axios = require('axios')

async function getWords() {
    const URL = 'https://nmsl.shadiao.app/api.php?lang=zh_cn&t='
    const RANDOM = Math.random().toString(32).substring(2,8);
    try {
        const res = await axios({
            url:URL+RANDOM,
            method: 'get'
        })
        if (res.status === 200) {
            let newWords = new Words({
                words:res.data
            })
            let saveStatus = await newWords.save()
            if (saveStatus.id != null ) {
                console.log('成功：'+res.data)
            } else {
                console.log('创建失败！')
            }
        }
    } catch(e) {
        console.log(e)
    }
}
let count = 0; 
const timer = setInterval(() => {
    getWords()
    if (count>2000) {
        clearInterval(timer);
        console.log('已完成！')
    } else {
        count+=1
    }
},200)




